package demo7;

import java.util.HashSet;
import java.util.Set;

public class StudentManager {
    private static Set<Student>students=new HashSet<>();
    static {
        students.add(new Student(1,"张三",18));
        students.add(new Student(2,"李四",18));
        students.add(new Student(3,"李四",18));
        students.add(new Student(4,"李三",18));
    }
    //遍历数组
    public static Set<Student>findAll(){
        return students;
    }
    //增加学员
    public static void adds(Student student){
            students.add(student);
    }
    //删除学员
    public static boolean deleteSong(int id){
        boolean flag=false;
        for (Student s:students) {
            if (id==s.getId()){
                students.remove(s);
                flag=true;
break;
            }
        }
      return flag;
    }
    //修改学员
    public static boolean mod(int id,String name,int age){
        boolean flag=false;
        for (Student a:students) {
            if (id==a.getId()){
               students.remove(a);
               students.add(new Student(id,name,age));
                flag=true;
                break;
            }
        }
      return flag;
    }
    //查询学员
    public static Set<Student> inquire(String name){
        Set<Student>students1=new HashSet<>();
        for (Student a:students) {
            if (a.getName().contains(name)){
                students1.add(a);
            }
        }
        return students1;
    }

    @Override
    public String toString() {
        return super.toString();
    }
}
